export CC		=gcc
export CFlag		:=-c -g -Wall -pg
export DFlag		:=-shared -fPID
export LFlag		:=-pg
export SHELL		=/bin/sh
# vpath works when find so file with in a prefix lib

vpath %.so ./bin

VPATH=./bin/
GPATH=./bin/

OBJ			=./src/main.o
TARGET			=./bin/a.out
inc			=./inc
subdirs			:=$(filter-out ./src/general,$(shell find ./src -name "??*" -type d | sed "1d"))
lib_llist		:=$(patsubst %,./bin/%.so,$(foreach dir,$(subdirs),$(notdir $(dir))))
INC			:=-I$(inc)



.SUFFIXES:
.SUFFIXES:.c .o .a .so
.PHONY:clean all MSG Libs_dp tar

ifeq ($(MAKELEVEL),0)
all:Libs_dp $(TARGET)
else
all:MSG
endif


Libs_dp:
	$(MAKE) -C ./src -w

$(TARGET):LFlag+=-L./bin
$(TARGET):$(OBJ) 
	$(CC) $(INC) $(LFlag) -o $@ $^ $(lib_llist)

$(OBJ):%.o:%.c
	$(CC) $(CFlag) $(INC) -o $@ $<

tar:
	tar -zcvf ../code-backup/data_struct.`date +"%y-%m-%d"`.tar.gz ./

MSG:
	-@echo "invoke makefile error. init makefile indeed."
	-@echo "MAKELEVEL = " $(MAKELEVEL)", " "but 0 required."

clean:
	-rm -f $(lib_llist) $(TARGET)
	$(MAKE) -C ./src -w clean

.INTERMEDIATE:$(OBJ)
